<?php

declare(strict_types=1);

namespace App\Chat\Controller;

use App\Chat\Annotation\ChatAuth;
use App\Chat\Constant\FollowUpTypeConstant;
use App\Chat\Request\TalkFollowUpTaskRequest;
use App\Chat\Service\TalkFollowUpTaskService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;

#[Controller(prefix: 'ch/chat/followuptask'),ChatAuth]
class TalkFollowUpTaskController extends ChatBaseController
{
    #[Inject]
    protected TalkFollowUpTaskService $service;


    #[PostMapping('list')]
    public function list(TalkFollowUpTaskRequest $request)
    {
        $data = $request->all();
        $data['select'] = 'id,type,time,content,status';
        return $this->success($this->service->getPageList($data,false));
    }

    /**
     * 新增
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('save')]
    public function save(): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->save($this->request->all()) ? $this->success() : $this->error();
    }

    /**
     * 获取跟进方式列表
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('getTypeList')]
    public function getTypeList(): \Psr\Http\Message\ResponseInterface
    {
        return $this->success(FollowUpTypeConstant::getOptions());
    }

    /**
     * 设置下次跟进时间
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('setNextFollowUpTime')]
    public function setNextFollowUpTime(): \Psr\Http\Message\ResponseInterface
    {
        $data = $this->request->all();
        return $this->service->setNextFollowUpTime($data) ? $this->success() : $this->error();
    }

    /**
     * 取消
     * @param TalkFollowUpTaskRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('cancel')]
    public function cancel(TalkFollowUpTaskRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->cancel($request->all()) ? $this->success() : $this->error();
    }
}